package cn.itrip.service.impl;

import cn.itrip.entity.ItripUserLinkUser;
import cn.itrip.dao.ItripUserLinkUserDao;
import cn.itrip.service.ItripUserLinkUserService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (ItripUserLinkUser)表服务实现类
 *
 * @author makejava
 * @since 2022-04-14 22:35:00
 */
@Service("itripUserLinkUserService")
public class ItripUserLinkUserServiceImpl implements ItripUserLinkUserService {
	@Resource
	private ItripUserLinkUserDao itripUserLinkUserDao;

	/**
	 * 通过ID查询单条数据
	 *
	 * @param id 主键
	 * @return 实例对象
	 */
	@Override
	public ItripUserLinkUser queryById(Long id) {
		return this.itripUserLinkUserDao.queryById(id);
	}

	/**
	 * 分页查询
	 *
	 * @param itripUserLinkUser 筛选条件
	 * @param pageRequest       分页对象
	 * @return 查询结果
	 */
	@Override
	public Page<ItripUserLinkUser> queryByPage(ItripUserLinkUser itripUserLinkUser, PageRequest pageRequest) {
		long total = this.itripUserLinkUserDao.count(itripUserLinkUser);
		return new PageImpl<>(this.itripUserLinkUserDao.queryAllByLimit(itripUserLinkUser, pageRequest), pageRequest, total);
	}

	/**
	 * 新增数据
	 *
	 * @param itripUserLinkUser 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripUserLinkUser insert(ItripUserLinkUser itripUserLinkUser) {
		this.itripUserLinkUserDao.insert(itripUserLinkUser);
		return itripUserLinkUser;
	}

	/**
	 * 修改数据
	 *
	 * @param itripUserLinkUser 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripUserLinkUser update(ItripUserLinkUser itripUserLinkUser) {
		this.itripUserLinkUserDao.update(itripUserLinkUser);
		return this.queryById(itripUserLinkUser.getId());
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 是否成功
	 */
	@Override
	public boolean deleteById(Long id) {
		return this.itripUserLinkUserDao.deleteById(id) > 0;
	}
}
